//
//  JHHotMusicTableViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHHotMusicTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface JHHotMusicTableViewCell ()

@property(nonatomic,retain)UIImageView *hotMusicBase;

@property(nonatomic,retain)UIImageView *hotMusicImage;
//@property(nonatomic,retain)UIButton *startButton;
@property(nonatomic,retain)UILabel *hotMusicTitle;

@property(nonatomic,retain)UIImageView *uSerImage;
@property(nonatomic,retain)UILabel *hotMusicUser;
@property(nonatomic,retain)UIImageView *playImage;
@property(nonatomic,retain)UILabel *hotMusicplay;
@property(nonatomic,retain)UIImageView *collectImage;
@property(nonatomic,retain)UILabel *hotMusicCollect;
@property(nonatomic,retain)UIImageView *commentImage;
@property(nonatomic,retain)UILabel *hotMusicComment;
@property(nonatomic,retain)UIImageView *durationImage;
@property(nonatomic,retain)UILabel *hotMusicDuration;
@end

@implementation JHHotMusicTableViewCell
- (void)dealloc
{
//    [_hotMusic release];
    [_hotMusicImage release];
    [_hotMusicCollect release];
    [_hotMusicComment release];
    [_hotMusicDuration release];
    [_hotMusicplay release];
    [_hotMusicTitle release];
    [_hotMusicUser release];
    [_collectImage release];
    [_commentImage release];
    [_playImage release];
    [_uSerImage release];
    [_durationImage release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //  底图
//        self.hotMusicBase = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_share_large"]] autorelease];
//        [self.contentView addSubview:_hotMusicBase];
        //  标题
        self.hotMusicTitle = [[[UILabel alloc] init]autorelease];
//        _hotMusicTitle.backgroundColor = [UIColor redColor];
        _hotMusicTitle.font = [UIFont systemFontOfSize:15];
        _hotMusicTitle.numberOfLines = 0;
        [self.contentView addSubview:_hotMusicTitle];
        //  头像
        self.hotMusicImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]] autorelease];
        _hotMusicImage.layer.cornerRadius = 24.5;
        _hotMusicImage.layer.masksToBounds = YES;
        [self.contentView addSubview:_hotMusicImage];
//        self.startButton = [UIButton buttonWithType:UIButtonTypeSystem];
//        [_startButton setImage:[UIImage imageNamed:@"iconfont-play"] forState:UIControlStateNormal];
//        [_hotMusicImage addSubview:_startButton];
        //  用户名
        self.uSerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-my"]]autorelease];
        [self.contentView addSubview:_uSerImage];
        self.hotMusicUser = [[[UILabel alloc] init] autorelease];
//        _hotMusicUser.backgroundColor = [UIColor yellowColor];
        _hotMusicUser.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_hotMusicUser];
        //  播放
        self.playImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-play"]] autorelease];
        [self.contentView addSubview:_playImage];
        self.hotMusicplay = [[[UILabel alloc] init] autorelease];
        _hotMusicplay.font = [UIFont systemFontOfSize:9];
//        _hotMusicplay.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_hotMusicplay];
        //  收藏
        self.collectImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-xiai"]]autorelease];
        [self.contentView addSubview:_collectImage];
        self.hotMusicCollect = [[[UILabel alloc] init] autorelease];
        _hotMusicCollect.font = [UIFont systemFontOfSize:9];
//        _hotMusicCollect.backgroundColor = [UIColor brownColor];
        [self.contentView addSubview:_hotMusicCollect];
        //  评论
        self.commentImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-mark"]] autorelease];
        [self.contentView addSubview:_commentImage];
        self.hotMusicComment = [[[UILabel alloc] init] autorelease];
        _hotMusicComment.font = [UIFont systemFontOfSize:9];
//        _hotMusicComment.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_hotMusicComment];
        //  时间
        self.durationImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-clock"]] autorelease];
        [self.contentView addSubview:_durationImage];
        self.hotMusicDuration = [[[UILabel alloc] init]autorelease];
        _hotMusicDuration.font = [UIFont systemFontOfSize:9];
//        _hotMusicDuration.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_hotMusicDuration];
        
    }return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
//    _hotMusicBase.frame = CGRectMake(0, 10, self.contentView.frame.size.width, self.contentView.frame.size.height - 20);

    _hotMusicImage.frame = CGRectMake(10, 10, self.contentView.frame.size.width / 5, self.contentView.frame.size.width / 5);
//    _startButton.frame = CGRectMake(20, 20, _hotMusicImage.frame.size.width - 40, _hotMusicImage.frame.size.height - 40);
    
    CGFloat f = [[self class] heightWithText:_hotMusicTitle.text];
    _hotMusicTitle.frame = CGRectMake(_hotMusicImage.frame.size.width + 20, 10, self.contentView.frame.size.width - _hotMusicImage.frame.size.width - 20, f );
    
    _uSerImage.frame = CGRectMake(_hotMusicImage.frame.size.width + 20, _hotMusicTitle.frame.size.height+ 10, 20, 20);
    _hotMusicUser.frame = CGRectMake(_uSerImage.frame.origin.x + _uSerImage.frame.size.width + 10, _hotMusicTitle.frame.size.height + 10, 150, 20);
    _playImage.frame = CGRectMake(_hotMusicImage.frame.size.width + 20, _hotMusicTitle.frame.size.height + 35, 15, 15);
    _hotMusicplay.frame = CGRectMake(_playImage.frame.origin.x + 25, _hotMusicTitle.frame.size.height + 35, 30, 15);
    _collectImage.frame = CGRectMake(_hotMusicplay.frame.origin.x + 40, _hotMusicTitle.frame.size.height + 35, 15, 15);
    _hotMusicCollect.frame = CGRectMake(_collectImage.frame.origin.x + 25, _hotMusicTitle.frame.size.height + 35, 30, 15);
    _commentImage.frame = CGRectMake(_hotMusicCollect.frame.origin.x + 20, _hotMusicTitle.frame.size.height + 35, 15, 15);
    _hotMusicComment.frame = CGRectMake(_commentImage.frame.origin.x + 20, _hotMusicTitle.frame.size.height + 35, 35, 15);
    _durationImage.frame = CGRectMake(_hotMusicComment.frame.origin.x + 30, _hotMusicTitle.frame.size.height + 35, 15, 15);
    _hotMusicDuration.frame = CGRectMake(_durationImage.frame.origin.x + 20, _hotMusicTitle.frame.size.height + 35, 35, 15);
    
}
- (void)setHotMusic:(JHHotMucis *)hotMusic
{
    if (hotMusic != _hotMusic) {
        [_hotMusic release];
        _hotMusic = [hotMusic retain];
    }
    [_hotMusicImage sd_setImageWithURL:[NSURL URLWithString:hotMusic.coverSmall]];
    _hotMusicTitle.text = hotMusic.title;
    _hotMusicUser.text = hotMusic.nickname;
    NSString *num = @"";
    if (hotMusic.playsCounts < 10000) {
        num = [NSString stringWithFormat:@"%ld",hotMusic.playsCounts];
    }else
        if (hotMusic.playsCounts > 10000) {
            //            NSInteger a = (recom.playsCounts / 10000.00);
            num = [NSString stringWithFormat:@"%.1f万",hotMusic.playsCounts / 10000.0];
        }

    _hotMusicplay.text = num;
    _hotMusicCollect.text = [hotMusic.sharesCounts description];
    _hotMusicComment.text = [hotMusic.commentsCounts description];
    NSString *miao = @"";
    if (hotMusic.duration % 60 < 10) {
        miao = [NSString stringWithFormat:@"0%ld",hotMusic.duration % 60];
    }else
        if (hotMusic.duration % 60 >10) {
            miao = [NSString stringWithFormat:@"%ld",hotMusic.duration % 60];
        }
    NSString *time = [NSString stringWithFormat:@"%ld:%@", hotMusic.duration / 60 , miao];
    
    _hotMusicDuration.text = time;
}
+ (CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    CGSize size = CGSizeMake( 250, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
